<?php
	class BlackListModel extends Model {
		function BlackListModel()
		{
			parent::Model();			
		}
		
		function add($data)
		{
			$this->db->set('is_active', '1', FALSE); 
			$this->db->set('create_date', 'NOW()', FALSE); 
			$this->db->set('create_by', "'". $this->session->userdata('username') ."'", FALSE);
			$this->db->insert('blacklist', $data);
			
			return $this->db->insert_id();
		}
		
		function removeFromPage($data) {
			$this->db->where('backlist_id', $data);
			$this->db->set('update_date', 'NOW()', FALSE);
            $this->db->set('is_active', '0', FALSE); 
            $this->db->set('update_by', "'". $this->session->userdata('username') ."'", FALSE);
			$this->db->update('blacklist'); 
		}
				
		function update($data)
		{			
            $this->db->where('backlist_id', $data['backlist_id']);
            $this->db->set('update_date', 'NOW()', FALSE); 
            $this->db->set('update_by', "'". $this->session->userdata('username') ."'", FALSE);
			$this->db->update('blacklist', $data); 
		}
		
		
		function getByKeyword($data)
		{
			if($data['name'] != null) {
				$this->db->or_like('first_name', $data['name']); 
				$this->db->or_like('last_name', $data['name']);
			}
			if($data['tel'] != null) {
				$this->db->or_like('telephone', $data['tel']);
			}
			$this->db->order_by("first_name", "asc"); 
			$this->db->order_by("last_name", "asc"); 
			$this->db->where('is_active', '1');
			$query = $this->db->get_where('blacklist');
			return $query->result();
		}
		
		function getByID($id)
		{
			$query = $this->db->get_where('blacklist', array('backlist_id' => $id, 'is_active' => '1'));
			return $query->row_array();
		}
		
		function getAll()
		{
			$this->db->where('is_active', '1');
			$this->db->order_by("first_name", "asc"); 
			$query = $this->db->get('blacklist');
			return $query->result();
		}
		
	}
?>